package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

//import com.ruoyi.mes.vo.sales.DeliverDetailVo;
import com.ruoyi.mes.domain.DeliverDetailVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.SleDeliver;
import com.ruoyi.mes.service.ISleDeliverService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发货通知Controller
 * 
 * @author CFL
 * @date 2024-04-28
 */
@RestController
@RequestMapping("/mes/deliver")
public class SleDeliverController extends BaseController
{
    @Autowired
    private ISleDeliverService sleDeliverService;

    /**
     * 查询发货通知列表
     */
    @PreAuthorize("@ss.hasPermi('mes:deliver:list')")
    @GetMapping("/list")
    public TableDataInfo list(SleDeliver sleDeliver)
    {
        startPage();
        List<SleDeliver> list = sleDeliverService.selectSleDeliverList(sleDeliver);
        return getDataTable(list);
    }

    /**
     * 导出发货通知列表
     */
    @PreAuthorize("@ss.hasPermi('mes:deliver:export')")
    @Log(title = "发货通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SleDeliver sleDeliver)
    {
        List<SleDeliver> list = sleDeliverService.selectSleDeliverList(sleDeliver);
        ExcelUtil<SleDeliver> util = new ExcelUtil<SleDeliver>(SleDeliver.class);
        util.exportExcel(response, list, "发货通知数据");
    }

    /**
     * 获取发货通知详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:deliver:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sleDeliverService.selectSleDeliverById(id));
    }


    /**
     * 根据id获取产品发货详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:deliver:query')")
    @GetMapping(value = "/getDetails")
    public TableDataInfo getProductInfo(@RequestParam Long orderId)
    {
        List<DeliverDetailVo> list = sleDeliverService.selectProductById(orderId);
        return getDataTable(list);
    }

    /**
     * 新增发货通知
     */
    @PreAuthorize("@ss.hasPermi('mes:deliver:add')")
    @Log(title = "发货通知", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SleDeliver sleDeliver)
    {
        return toAjax(sleDeliverService.insertSleDeliver(sleDeliver));
    }

    /**
     * 修改发货通知
     */
    @PreAuthorize("@ss.hasPermi('mes:deliver:edit')")
    @Log(title = "发货通知", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SleDeliver sleDeliver)
    {
        return toAjax(sleDeliverService.updateSleDeliver(sleDeliver));
    }

    /**
     * 删除发货通知
     */
    @PreAuthorize("@ss.hasPermi('mes:deliver:remove')")
    @Log(title = "发货通知", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sleDeliverService.deleteSleDeliverByIds(ids));
    }
}
